package com.shine.chemicalWholeProcessSystem.ui.search;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.lxj.xpopup.interfaces.SimpleCallback;
import com.shine.chemicalWholeProcessSystem.BR;
import com.shine.chemicalWholeProcessSystem.R;
import com.shine.chemicalWholeProcessSystem.app.Constants;
import com.shine.chemicalWholeProcessSystem.base.BaseActivity;
import com.shine.chemicalWholeProcessSystem.databinding.ActivitySearchBinding;
import com.shine.chemicalWholeProcessSystem.ui.adapter.SearchFragmentPageAdapter;
import com.shine.chemicalWholeProcessSystem.ui.fragment.SearchChild1Fragment;
import com.shine.chemicalWholeProcessSystem.ui.fragment.SearchChild2Fragment;
import com.shine.chemicalWholeProcessSystem.ui.fragment.SearchChild3Fragment;
import com.shine.chemicalWholeProcessSystem.view.pop.SearchBottomPopup;

import java.util.ArrayList;
import java.util.List;

public class SearchActivity extends BaseActivity<ActivitySearchBinding, SearchViewModel> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_search;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public SearchViewModel initViewModel() {
        return new SearchViewModel(this);
    }

    @Override
    public int appTheme() {
        return Constants.THEME_FULL;
    }

    @Override
    public void initData() {
        super.initData();
        setStatusBar();

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new SearchChild1Fragment());
        fragmentList.add(new SearchChild2Fragment());
        fragmentList.add(new SearchChild3Fragment());

        SearchFragmentPageAdapter searchFragmentPageAdapter = new SearchFragmentPageAdapter(this, fragmentList);
        binding.viewPage2.setAdapter(searchFragmentPageAdapter);

        TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(binding.tabLayout, binding.viewPage2,true,  new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                switch (position){
                    case 0:
                        tab.setText("tab1");
                        break;
                    case 1:
                        tab.setText("tab2");
                        break;
                    case 2:
                        tab.setText("tab3");
                        break;
                }
            }
        });
        tabLayoutMediator.attach();

        binding.search.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.search:
                SearchBottomPopup searchBottomPopup = new SearchBottomPopup(this);
                new XPopup.Builder(SearchActivity.this)
                        .moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                        .enableDrag(true)
                        .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .isThreeDrag(true) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                        .setPopupCallback(new SimpleCallback() {
                            @Override
                            public void onShow(BasePopupView popupView) {
                            }

                            @Override
                            public void onDismiss(BasePopupView popupView) {
                            }
                        })
                        .asCustom(searchBottomPopup)/*.enableDrag(false)*/
                        .show();
                searchBottomPopup.show();
                searchBottomPopup.setListener(new OnConfirmListener() {
                    @Override
                    public void onConfirm() {
                    }
                }, new OnCancelListener() {
                    @Override
                    public void onCancel() {

                    }
                });
                break;
            default:
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                default:
                    break;
            }
        }
    }
}
